//
//  UIColor+XYColor.m
//  NemoSDKDemo
//
//  Created by 高超 on 2020/7/28.
//  Copyright © 2020 JackYang. All rights reserved.
//

#import "UIColor+XYColor.h"

@implementation UIColor (XYColor)

+ (UIColor *)colorWithHexString:(NSString *)hex {
    return [UIColor colorWithHexString:hex withAlpha:1];
}

+ (UIColor *)colorWithHexString:(NSString *)hex withAlpha:(CGFloat)alpha {
    unsigned rgbValue = 0;
    NSScanner *scanner = [NSScanner scannerWithString:hex];
    [scanner setCharactersToBeSkipped:[NSCharacterSet characterSetWithCharactersInString:@"#"]];
    [scanner scanHexInt:&rgbValue];
    return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 green:((rgbValue & 0xFF00) >> 8)/255.0 blue:(rgbValue & 0xFF)/255.0 alpha:alpha];
}

+ (UIColor *(^)(int, float))Color{
    return ^(int tone, float alpha){
        return [UIColor colorWithRed:((tone & 0xFF0000) >> 16)/255.0 green:((tone & 0xFF00) >> 8)/255.0 blue:((tone & 0xFF))/255.0 alpha:alpha];
    };
}

+ (UIColor *(^)(CGFloat))white{
    return ^(CGFloat alpha){
        return self.Color(0xffffff, alpha);
    };
}

+ (UIColor *(^)(CGFloat))black{
    return ^(CGFloat alpha){
        return self.Color(0x000000, alpha);
    };
}

@end
